using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
     class MRPMasterRequirementService
    {
        ISession session;

        public MRPMasterRequirementService(ISession session)
        {
            this.session = session;
        }
        public MRPMasterRequirementService( )
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpmasterrequirement(MRPMasterRequirement mrpmasterrequirementX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpmasterrequirementX);
            tx.Commit();
        }

        public void UpdateMrpmasterrequirement(MRPMasterRequirement mrpmasterrequirementX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpmasterrequirementX);
            tx.Commit();
        }

        public void DeleteMrpmasterrequirement(MRPMasterRequirement mrpmasterrequirementX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpmasterrequirementX);
            tx.Commit();
        }

        public IList<MRPMasterRequirement> GetAllMrpmasterrequirement(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPMasterRequirement");
            IList<MRPMasterRequirement> list = query.List<MRPMasterRequirement>();
            if (evict)
            {
                foreach (MRPMasterRequirement s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPMasterRequirement GetAllMrpmasterrequirementByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPMasterRequirement as c where c.Requirementcode= :x");
            query.SetString("x", id);
            MRPMasterRequirement s = (MRPMasterRequirement)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPMasterRequirement> GetMrpmasterrequirementByQuery(IQuery query, Boolean evict)
        {
            IList<MRPMasterRequirement> list = query.List<MRPMasterRequirement>();
            if (evict)
            {
                foreach (MRPMasterRequirement s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

    }
}
